import { ActionType, ModalForm, ProFormText, ProFormTreeSelect, ProTable } from "@ant-design/pro-components";
import React, { PropsWithChildren, ReactElement, useRef, useState } from "react";
import { Input } from "antd";

export default function ArticleModalSelect({
  value,
  onChange,
  children,
                                          }:PropsWithChildren<{
  value?: number;
  onChange?: (value?: number, fullValue?: API.PageAnchorListVo)=>void
}>){
  const [selections,setSelections] = useState<API.PageAnchorListVo>();

  const actionRef = useRef<ActionType>();

  return <>
    <ModalForm
      layout="horizontal"
      width={800}
      modalProps={{
        bodyStyle: {
          marginTop: 20,
        },
        maskClosable: false,
      }}
      onOpenChange={(val) => {
        if (val) {
          actionRef.current?.reset?.();
        }
      }}
      title="选择主播"
      trigger={
        children as ReactElement ?? <Input />
      }
      onFinish={() => {
        onChange?.(selections?.id, selections);
        return Promise.resolve(true);
      }}
    >
      <ProTable<API.PageAnchorListVo>
        toolBarRender={false}
        actionRef={actionRef}
        rowKey="id"
        search={{
          labelWidth: 100,
          style: {
            padding: 0,
          }
        }}
        rowSelection={{
          type: 'radio',
          selections: selections ? [selections.id!] : [],
          onChange: (selectedRowKeys, selectedRows, info)=>{
            setSelections(selectedRows[0]);
          }
        }}
        request={(params) => {
          const {
            pageSize,
            current,
            nickName,
            code,
          } = params;
          /*return AnchorControllerPageList({
            pageSize,
            pageNum: current,
            param: {
              nickName,
              code,
            },
          }).then((res) => {
            return {
              success: true,
              data: res.records,
              total: res.totalCount,
            };
          });*/
        }}
        columns={[
          {
            title: '主播ID',
            key: 'code',
            hideInTable: true,
          },
          {
            title: '昵称',
            key: 'nickName',
            hideInTable: true,
          },
          {
            title: '公会/经纪人',
            dataIndex: 'ownerName',
            search: false,
          },
        ]}
      />
    </ModalForm>

  </>
}
